package com.game.dao.user;

import com.coment.po.UserPlayInfo;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface UserPlayInfoDao extends MongoRepository<UserPlayInfo, Integer> {
    default UserPlayInfo findByUserInfoIdOrCreate(Integer userInfoId) {
        return findById(userInfoId).orElseGet(() -> {
            UserPlayInfo userPlayInfo = new UserPlayInfo();
            userPlayInfo.setUserInfoId(userInfoId);
            return save(userPlayInfo);
        });
    }
    /// 更新最近游玩的房间
    @Query("{ userInfoId: ?0 }")
    @Update("{ $set: { recentlyPlayedAnchorInfoId: ?1 } }")
    void updateRecentlyPlayedAnchorInfoId(Integer userInfoId, Integer recentlyPlayedAnchorInfoId);

    /// 更新最近游玩的角色
    @Query("{ userInfoId: ?0 }")
    @Update("{ $set: { recentlyPlayedRolesId: ?1 } }")
    void updateRecentlyPlayedRolesId(Integer userInfoId, String recentlyPlayedRolesId);

    /// 更新最近出战宠物
    @Query("{ userInfoId: ?0 }")
    @Update("{ $set: { recentlyPlayedPetId: ?1 } }")
    void updateRecentlyPlayedPetId(Integer userInfoId, int recentlyPlayedPetId);
}
